package com.xiexin.web.controller.setmealinfo;

import com.xiexin.common.annotation.Log;
import com.xiexin.common.core.controller.BaseController;
import com.xiexin.common.core.domain.AjaxResult;
import com.xiexin.common.core.page.TableDataInfo;
import com.xiexin.common.enums.BusinessType;
import com.xiexin.common.utils.poi.ExcelUtil;
import com.xiexin.setmealinfo.domain.SetmealInfo;
import com.xiexin.setmealinfo.service.ISetmealInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * 套餐的信息Controller
 *
 * @author xiexin
 * @date 2022-03-26
 */
@RestController
@RequestMapping("/setmealinfo/setmealinfo")
public class SetmealInfoController extends BaseController {
    @Autowired
    private ISetmealInfoService setmealInfoService;


    @GetMapping("/listByPhone") // /setmealinfo/setmealinfo/listByPhone
    public TableDataInfo listByPhone(SetmealInfo setmealInfo) {
        startPage();
        List<SetmealInfo> list = setmealInfoService.selectSetmealInfoList(setmealInfo);
        return getDataTable(list);
    }

    @GetMapping ("/id")
    public AjaxResult getIdInfo( Long id) {
        return AjaxResult.success(setmealInfoService.selectSetmealInfoById(id));
    }


    /**
     * 查询套餐的信息列表
     */
    @PreAuthorize("@ss.hasPermi('setmealinfo:setmealinfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(SetmealInfo setmealInfo) {
        startPage();
        List<SetmealInfo> list = setmealInfoService.selectSetmealInfoList(setmealInfo);
        return getDataTable(list);
    }

    /**
     * 导出套餐的信息列表
     */
    @PreAuthorize("@ss.hasPermi('setmealinfo:setmealinfo:export')")
    @Log(title = "套餐的信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SetmealInfo setmealInfo) {
        List<SetmealInfo> list = setmealInfoService.selectSetmealInfoList(setmealInfo);
        ExcelUtil<SetmealInfo> util = new ExcelUtil<SetmealInfo>(SetmealInfo.class);
        util.exportExcel(response, list, "套餐的信息数据");
    }

    /**
     * 获取套餐的信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('setmealinfo:setmealinfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(setmealInfoService.selectSetmealInfoById(id));
    }

    /**
     * 新增套餐的信息
     */
    @PreAuthorize("@ss.hasPermi('setmealinfo:setmealinfo:add')")
    @Log(title = "套餐的信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SetmealInfo setmealInfo) {
        return toAjax(setmealInfoService.insertSetmealInfo(setmealInfo));
    }

    /**
     * 新增套餐的信息
     */
    @PreAuthorize("@ss.hasPermi('setmealinfo:setmealinfo:add')")
    @Log(title = "套餐的信息", businessType = BusinessType.INSERT)
    @PostMapping("/addSetmealAndIds")
    public AjaxResult add1(@RequestBody Map data) {
        System.out.println("data = " + data);
        return toAjax(1);
    }

    /**
     * 修改套餐的信息
     */
    @PreAuthorize("@ss.hasPermi('setmealinfo:setmealinfo:edit')")
    @Log(title = "套餐的信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SetmealInfo setmealInfo) {
        return toAjax(setmealInfoService.updateSetmealInfo(setmealInfo));
    }

    /**
     * 删除套餐的信息
     */
    @PreAuthorize("@ss.hasPermi('setmealinfo:setmealinfo:remove')")
    @Log(title = "套餐的信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(setmealInfoService.deleteSetmealInfoByIds(ids));
    }



}
